package com.acwing.partition12;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/31 10:21
 */
public class AC1113红与黑 {

    private static final int N = 25, M = 25;
    private static char[][] graph = new char[N][M];
    private static boolean[][] visited = new boolean[N][M];
    private static int n = -1, m = -1;
    private static final int[][] dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        while (true) {
            String str = reader.readLine();
            String[] s = str.split("\\s+");
            m = Integer.parseInt(s[0]);
            n = Integer.parseInt(s[1]);
            if (n == 0 && m == 0) break;
            for (int i = 0; i < n; i++) {
                str = reader.readLine();
                for (int j = 0; j < m; j++) graph[i][j] = str.charAt(j);
            }
            //找到起点
            int x = -1, y = -1;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    visited[i][j] = false;
                    if (graph[i][j] == '@') {
                        x = i;
                        y = j;
                    }
                }
            }
            writer.write(dfs(x, y) + "\n");
        }
        writer.flush();
    }

    private static int dfs(int x, int y) {
        visited[x][y] = true;
        int ans = 1;
        for (int[] dir : dirs) {
            int nextX = x + dir[0], nextY = y + dir[1];
            if (nextX < 0 || nextX >= n || nextY < 0 || nextY >= m) continue;
            if (visited[nextX][nextY] || graph[nextX][nextY] == '#') continue;
            ans += dfs(nextX, nextY);
        }
        return ans;
    }
}
